﻿using UtilZ.Dotnet.Ex.Base;

namespace UtilZ.Dotnet.Ex.Communication.Base
{
    /// <summary>
    /// IClient心跳接口
    /// </summary>
    public interface IClientHeart
    {
        /// <summary>
        /// 心中数据发送间隔毫秒数
        /// </summary>
        int HeartIntervalMilliseconds { get; }

        /// <summary>
        /// 发送心跳数据buffer
        /// </summary>
        /// <param name="client">用于发送心跳数据Client</param>
        void SendHeartData(IClient client);
    }

    /// <summary>
    /// IClient心跳基类
    /// </summary>
    public abstract class ClientHeartAbs : IClientHeart
    {
        private readonly int _heartIntervalMilliseconds;
        /// <summary>
        /// 心跳数据发送间隔毫秒数
        /// </summary>
        public int HeartIntervalMilliseconds
        {
            get { return this._heartIntervalMilliseconds; }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="heartIntervalMilliseconds">心跳数据发送间隔毫秒数</param>
        public ClientHeartAbs(int heartIntervalMilliseconds)
        {
            this._heartIntervalMilliseconds = heartIntervalMilliseconds;
        }


        /// <summary>
        /// 发送心跳数据buffer
        /// </summary>
        /// <param name="client">用于发送心跳数据Client</param>
        public void SendHeartData(IClient client)
        {
            this.SendHeartData(client);
        }

        /// <summary>
        /// 发送心跳数据buffer
        /// </summary>
        /// <param name="client">用于发送心跳数据Client</param>
        protected abstract void PrimitiveSendHeartData(IClient client);

    }

}
